package com.deploy.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 服务器信息模型类
 * 存储目标服务器的连接信息
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ServerInfo {
    /**
     * 服务器IP地址
     */
    private String ip;
    
    /**
     * 登录用户名
     */
    private String username;
    
    /**
     * 登录密码
     */
    private String password;
    
    /**
     * SSH端口，默认为22
     */
    private int port = 22;
    /**
     * 当前Agent文件路径
     */
    private String currentAgentFilePath = "software/agent";

    /**
     * 当前配置文件路径
     */
    private String currentConfigFilePath = "software/application.yaml";
    
    /**
     * 目标部署路径
     */
    private String deployPath = "/home/software/";
    
    /**
     * 操作系统类型，默认为LINUX
     */
    private OsType osType = OsType.LINUX;
    
    /**
     * 操作系统类型枚举
     */
    public enum OsType {
        /**
         * Linux操作系统
         */
        LINUX,
        
        /**
         * Windows操作系统
         */
        WINDOWS
    }
    
    /**
     * 获取格式化后的部署路径
     * 确保Linux路径以/结尾，Windows路径以\结尾
     *
     * @return 格式化后的部署路径
     */
    public String getFormattedDeployPath() {
        if (osType == OsType.WINDOWS) {
            // 确保Windows路径使用反斜杠并以反斜杠结尾
            String path = deployPath.replace('/', '\\');
            return path.endsWith("\\") ? path : path + "\\";
        } else {
            // 确保Linux路径以斜杠结尾
            return deployPath.endsWith("/") ? deployPath : deployPath + "/";
        }
    }
    
    @Override
    public String toString() {
        return "ServerInfo{" +
                "ip='" + ip + '\'' +
                ", username='" + username + '\'' +
                ", password='******'" +
                ", port=" + port +
                ", deployPath='" + deployPath + '\'' +
                ", osType=" + osType +
                '}';
    }
}
